
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression



#-------------------------------------#
#   设置数据集的路径
#   csv_path   训练集数据和标签
#   valid_csv_path   验证集数据和标签
#-------------------------------------#
train_csv_path   = "../cls_train.csv"
valid_csv_path   = "../cls_valid.csv"


if __name__ == "__main__":

    #----------------------#
    #   读取数据集对应的csv
    #----------------------#
    train_csv = pd.read_csv(train_csv_path)
    train_data = np.array(train_csv)

    valid_csv = pd.read_csv(valid_csv_path)
    valid_data = np.array(valid_csv)

    num_train = len(train_data)
    num_val = len(valid_data)

    print(f"训练样本数量:{num_train}, 验证样本数量:{num_val}")
    train_x, train_y = train_data[:, :-1], train_data[:, -1].astype(int)
    valid_x, valid_y = valid_data[:, :-1], valid_data[:, -1].astype(int)

    print("LR")
    model = LogisticRegression(random_state=0, max_iter=1000, multi_class='multinomial')
    model.fit(train_x, train_y)
    train_score = model.score(train_x, train_y)
    print("训练集：", train_score)
    test_score = model.score(valid_x, valid_y)
    print("测试集：", test_score)


